package com.wtgroup.demo.mianshi.容器.链表;

import com.wtgroup.demo.common.bean.DoubleNode;

/**
 * @author dafei
 * @version 0.1
 * @date 2021/4/16 15:48
 */
public class D2_双链表反转 {

    public static void main(String[] args) {
        DoubleNode node = DoubleNode.toDoubleNode(1, 2, 3, 4, 5, 6, 7, 8);
        DoubleNode res = run(node);
        DoubleNode.print(res);
    }

    public static DoubleNode run(DoubleNode head) {
        DoubleNode prev = null;
        DoubleNode next = null;
        while (head != null) {
            next = head.next;
            head.next = prev;
            if (prev != null) {
                prev.prev = head;
            }
            prev = head;
            head = next;
        }

        return prev;
    }


}
